<!-- 应用管理 - 新增/编辑应用 -->
<template>
    <div class="rightCenter">
        <div class="editTop">
            <div class="editTopTitle" @click="cancelClick()">应用管理</div>
            <i class="icon font_family icon-yema-you"></i>
            <div class="editTopTitle">{{editVal}}</div>
        </div>
        <div class="editList">
            <div class="editListName">
                应用名称：
            </div>
            <input class="editListInpBox fontBlue" v-model.trim='nameVal' type="text" placeholder="名称为中文、英文、数字不超过15个字符" maxlength="15">
            <span class="warn" v-show='titleShow'>请输入应用名称</span>
        </div>
          <div class="editList">
            <div class="editListName">
                应用报名：
            </div>
            <input class="editListInpBox fontBlue" v-model.trim='packageNameVal' type="text" placeholder="包名不超过50个字符" maxlength="50">
            <span class="warn" v-show='titleShow'>请输入应用包名</span>
        </div>
        <div class="footButton">
            <div class="addBut" @click='addClick'>
                保 存
            </div>
            <div class="cancelBut" @click='cancelClick'>
                取 消
            </div>
        </div>
    </div>
</template>
<script>
import { mapActions } from "vuex";
import useRequest from "../../assets/use";
export default {
  data() {
    return {
      appIdVal: "",
      nameVal: "",
      packageNameVal: "",
      providerIdVal: "",
      editVal: "新增应用",
      titleShow: false
    };
  },
  filters: {},
  created: function() {
    let self = this;
    if (sessionStorage.getItem("TABLIST")) {
      let arr = JSON.parse(sessionStorage.getItem("TABLIST"));
      let routShow = false;
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].name == "应用管理") {
          routShow = true;
        }
      }
      if (!routShow) {
        this.$router.push({
          path: "/login"
        });
        sessionStorage.clear();
        self.$message("暂无权限");
        return;
      }
    }else{
       this.$router.push({
          path: "/login"
        });
        sessionStorage.clear();
        self.$message("暂无权限");
        return;
    }
    self.listFun();
  },
  watch: {},
  mounted() {},
  methods: {
    async listFun() {
      let self = this;
      let params = {
        appId: self.$route.query.appId
      };
      let getParams = `appId=${params.appId}`;
      let res = await useRequest.getappInfo(getParams);
      if (res.statusCode == 200) {
        if (res.data) {
          self.nameVal = res.data.name;
          self.packageNameVal = res.data.packageName;
        }
      } else {
        self.$message(res.statusMessage);
        self.dataList = [];
      }
    },
    cancelClick() {
      this.$router.push({
        path: "/home/use"
      });
    },
    //保存
    async addClick() {
      let self = this;
      let params = {
        appId: self.$route.query.appId,
        name: self.nameVal,
        packageName: self.packageNameVal
      };
      let res = await useRequest.getappupdate(params);
      if (res.statusCode == 200) {
        self.$message("修改应用成功！");
        self.cancelClick();
      } else {
        self.$message(res.statusMessage);
      }
    }
  }
};
</script>
<style scoped>
.editUpImgHand {
  width: 200px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  background: #f2f5f7;
  color: #b2b7c0;
}

.editUpImgHand i {
  font-size: 20px;
}

.textBox {
  width: 350px;
  min-height: 80px;
  line-height: 24px;
  font-size: 14px;
  background: #f2f5f7;
  margin-left: 12px;
  padding: 4px 8px;
  margin-right: 14px;
  resize: none;
}

.issue {
  width: 450px;
}

.issueSelect {
  display: flex;
  margin: 12px;
}

.issueTrue {
  height: 40px;
  line-height: 40px;
}

.issueCheck {
  margin: 10px;
}

.isuueInd {
  width: 40px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  color: #000;
}

.issueInp {
  width: 230px !important;
  height: 40px !important;
}

.issueButton {
  display: flex;
  margin: 12px;
}

.fontBlue {
  color: #2f3a5d;
  font-size: 14px;
  font-weight: bold;
}

.banckBlue {
  background: #279de2;
}

.banckRed {
  background: #ed4a47;
  margin: 0 24px;
}

.prizeDelect {
  background: #ed4a47;
  margin: 0 12px;
}

.prizeBox {
  width: 450px;
  padding: 4px 8px;
}

.prize {
  margin-bottom: 14px;
}

.prizeFoot {
  margin-top: 14px;
}

.prizeFoot,
.prizeTop {
  display: flex;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 14px;
  font-weight: bold;
  color: #2f3a5d;
}

.prizeTopInd {
  margin-right: 14px;
}

.prizeTopSelect {
  margin: 0 14px;
}

.prizeFootSelect {
  margin: 0 14px;
}

.prizeFootInp {
  width: 60px;
  height: 40px;
  margin: 0 14px;
  padding: 0 5px;
  background: #f2f5f7;
}

.addPrize {
  width: 110px;
  height: 40px;
  font-size: 16px;
  line-height: 40px;
  text-align: center;
  cursor: pointer;
  background: #279de2;
  margin: 14px;
}

.explain {
  font-size: 14px;
  padding: 14px 8px;
  line-height: 24px;
  color: #2f3a5d;
  font-weight: bold;
}

.timeBox {
  display: flex;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 14px;
  font-weight: bold;
  margin-top: 10px;
  color: #2f3a5d;
}

.footButton {
  display: flex;
  width: 700px;
  align-items: center;
  margin-top: 124px;
  margin-left: 230px;
}

.addBut {
  width: 150px;
  height: 50px;
  border-radius: 25px;
  text-align: center;
  line-height: 50px;
  cursor: pointer;
  margin: 0 12px;
  background: #279de2;
  color: white;
}

.cancelBut {
  width: 150px;
  height: 50px;
  border-radius: 25px;
  text-align: center;
  line-height: 50px;
  cursor: pointer;
  margin: 0 12px;
  border: 1px solid #279de2;
  color: #279de2;
}
</style>